package com.leetcode.partition6;

import java.util.Arrays;
import java.util.PriorityQueue;

/**
 * @author `RKC`
 * @date 2021/12/2 15:34
 */
public class LC506相对名次 {

    private static final String[] topThree = {"Gold Medal", "Silver Medal", "Bronze Medal"};

    public static String[] findRelativeRanks(int[] score) {
        String[] answer = new String[score.length];
        //大顶堆存放一个二元组 (分数, 分数对应的下标)
        PriorityQueue<int[]> queue = new PriorityQueue<>((o1, o2) -> Integer.compare(o2[0], o1[0]));
        for (int i = 0; i < score.length; i++) queue.add(new int[]{score[i], i});
        for (int i = 0; i < score.length; i++) {
            int[] tuple = queue.poll();
            if (i < 3) {
                answer[tuple[1]] = topThree[i];
                continue;
            }
            answer[tuple[1]] = String.valueOf(i + 1);
        }
        return answer;
    }

    public static void main(String[] args) {
//        int[] score = {5, 4, 3, 2, 1};
        int[] score = {10, 3, 8, 9, 4};
        System.out.println(Arrays.toString(findRelativeRanks(score)));
    }
}
